package com.cy.improve.demos.web.elasticsearch;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch.core.IndexResponse;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.client.RestClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
@Slf4j
@RestController
public class ESController {
    @Resource
    private ElasticsearchClient esClient;


    @GetMapping("create")
    public String index() throws IOException {

        esClient.indices().create(c -> c
                .index("business-log")
        );


        // IndexResponse response = esClient.index(i -> i
        //         .index("products")
        //         .id(product.getSku())
        //         .document(product)
        // );

        // log.info("Indexed with version " + response.version());


        return "ok";
    }



    // @GetMapping("es/quety")
    // public void query{
    //
    //     SearchResponse<Product> search = esClient.search(s -> s
    //                     .index("products")
    //                     .query(q -> q
    //                             .term(t -> t
    //                                     .field("name")
    //                                     .value(v -> v.stringValue("bicycle"))
    //                             )),
    //             Product.class);
    //
    //     for (Hit<Product> hit: search.hits().hits()) {
    //         processProduct(hit.source());
    //     }
    // }

}
